//
//  YonghuSTableViewCell.m
//  XRSquare
//
//  Created by UaenaMo on 2018/8/15.
//  Copyright © 2018年 UaenaMo. All rights reserved.
//

#import "YonghuSTableViewCell.h"

@interface YonghuSTableViewCell ()
{
    UIImageView * avatar;
    UILabel * name;
    UIButton * addButton;
    NSDictionary * currentData;
}
@end

@implementation YonghuSTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        avatar = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 50, 50)];
        avatar.layer.cornerRadius = 25;
        avatar.clipsToBounds = YES;
        [self addSubview:avatar];
        
        name = [[UILabel alloc]initWithFrame:CGRectMake(70, 10, ScreenWidth - 80 - 70, 50)];
        name.font = [UIFont boldSystemFontOfSize:15];
        name.clipsToBounds = YES;
        [self addSubview:name];
        
        addButton = [[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth - 80, 20, 60, 30)];
        addButton.layer.cornerRadius = 15;
        addButton.layer.borderColor = themeColor.CGColor;
        addButton.layer.borderWidth = 1;
        addButton.titleLabel.font = [UIFont systemFontOfSize:15];
        [addButton setTitleColor:themeColor forState:UIControlStateNormal];
        [addButton addTarget:self action:@selector(optionAction) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:addButton];
        
        UIView * line = [[UIView alloc]initWithFrame:CGRectMake(0, 69, ScreenWidth, 1)];
        line.backgroundColor = [UIColor colorFromHexCode:@"f3f3f3"];
        [self addSubview:line];
        
    }
    return self;
}

+(CGFloat)height
{
    return 70;
}

-(void)loadData:(NSDictionary *)data
{
    currentData = data;
    [avatar sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://pic.xrsquare.com/%@",[data objectForKey:@"HeadPic"]]]];
    name.text = [data objectForKey:@"Name"];
    if ([[[data objectForKey:@"friendStatus"]objectForKey:@"status"]isEqualToNumber:@0])
    {
        addButton.enabled = NO;
        [addButton setTitle:[[data objectForKey:@"friendStatus"]objectForKey:@"msg"] forState:UIControlStateNormal];
    }
    else if ([[[data objectForKey:@"friendStatus"]objectForKey:@"status"]isEqualToNumber:@1])
    {
        addButton.enabled = YES;
        [addButton setTitle:@"删除" forState:UIControlStateNormal];
    }
    else
    {
        addButton.enabled = YES;
        [addButton setTitle:[[data objectForKey:@"friendStatus"]objectForKey:@"msg"] forState:UIControlStateNormal];
    }
}

-(void)optionAction
{
    if ([[[currentData objectForKey:@"friendStatus"]objectForKey:@"status"]isEqualToNumber:@0])
    {
    
    }
    else if ([[[currentData objectForKey:@"friendStatus"]objectForKey:@"status"]isEqualToNumber:@1])
    {
        [self.delegate deleteAction:[currentData objectForKey:@"FriendUid"]];
    }
    else
    {
        [self.delegate adadAction:[currentData objectForKey:@"FriendUid"]];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
